package internationalenergytradingplatform.dao;

import internationalenergytradingplatform.pojo.BuyerAccount;
import internationalenergytradingplatform.pojo.BuyerBalance;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BuyerAccountDao {
    /**
     *
     * @author yingfeng
     * @date 2024/3/20 14:46
    根据采购商公司账号（手机号）名称查询采购商公司账号
     */
    @Select("select * from INTERNATIONAL_ENERGY_CONNECT_DB.buyer_accountr_tb where tele = #{tele}")
    BuyerAccount getBuyerByTele(String tele);

    /**
     *
     * @author yingfeng
     * @date 2024/3/25 18:29
     更新余额
     */
    @Update("update buyer_accountr_tb set balance = #{balance} where tele = #{tele}")
    void updateBalance(@Param("balance") Double balance, @Param("tele") String tele);

    /**
     * 记录更新余额
     */
    @Insert("insert into buyer_balance_change_tb values(null, #{time}, #{type}, #{balance}, #{source}, #{account})")
    void insertUpdateBalance(BuyerBalance buyerBalance);

    /**
     * 修改采购商地址
     */
    @Update("update buyer_accountr_tb set address = #{address} where tele = #{tele}")
    void updateAddress(@Param("tele") String tele, @Param("address") String address);

    /**
     * 更新采购商状态
     * @param tele
     * @param state
     * @return
     */
    @Update("UPDATE buyer_accountr_tb SET buyer_accountr_status = #{state} WHERE tele = #{tele}")
    int updateBuyerAccountState(@Param("tele") String tele, @Param("state") Integer state);

    /**
     *
     * @author yingfeng
     * @date 2024/4/3 23:22
     获取全部采购商
     */
    @Select("select * from INTERNATIONAL_ENERGY_CONNECT_DB.buyer_accountr_tb")
    List<BuyerAccount> getAllBuyerAccount();

    /**
     *
     * @author yingfeng
     * @date 2024/4/26 18:00
     * 获取采购商余额
     */
    @Select("select balance from buyer_accountr_tb where tele"+
    "=#{tele}")
    Double getBuyerBalance(@Param("tele") String tele);

}
